import React from 'react'
import PropTypes from 'prop-types';
class MyAlert extends React.Component{
    constructor(props){
        const $el=document.querySelector("#alert")
       
        if($el&&$el.childNodes.length){
            $el.parentNode.removeChild($el);
        }
        
        super(props);
        
    }
    ensureFn(){
        let {$el}=this.props;
        if($el){
            if($el.current){
                $el=$el.current
            }
            $el.parentNode.removeChild($el)
        }
        // 
        if(typeof this.props.fn=="function"){
            this.props.fn();
        }
    }
    render(){
        return (
            <div className="comm_alert">
                <div className="comm_alert_content">
                    <h3>{this.props.title||"默认标题"}</h3>
                    <div className="pd_10">
                        <div className="comm_alert_cont">
                            <div><span>{this.props.message||"默认区域的类容"}</span></div>
                        </div>
                    </div>
                    <button className="ensure-btn" onClick={()=>{this.ensureFn()}}>{this.props.ensureBtn||'确定'}</button>
                </div>
            </div>
        )
    }
}
MyAlert.propTypes ={
    title:PropTypes.string,
    message:PropTypes.string,
    ensureBtn:PropTypes.string,
    fn:PropTypes.func,
    $el:PropTypes.object
}
export default MyAlert;